﻿using MiniExcelLibs;
using MiniExcelLibs.Attributes;
using System.Text.RegularExpressions;

namespace _car_出租车题库选项提取
{
    internal class Program
    {
        static void Main(string[] args)
        {

            string input = "经过大庆市的国道有(C)。";
            string output = Regex.Replace(input, @"\([^)]*\)", "()");

            Console.WriteLine(output);
            using (Stream stream = File.OpenRead("C:\\Users\\hu\\Desktop\\output3xlsx.xlsx"))
            {
                List<string> list = new List<string>();
                var questionInputs = stream.Query<QuestionCar>().ToList();
                if (questionInputs == null || questionInputs.Count == 0)
                {
                    return;
                }
                List<QuestionOutCar> outCar = new List<QuestionOutCar>();
                foreach (var questionInput in questionInputs)
                {
                    QuestionOutCar questionOutCar = new QuestionOutCar();
                    MatchCollection matches3 = Regex.Matches(questionInput.Options, @"(\w)\s、(.+?)(?=\w\s、|$)");
                    questionOutCar.Content = Regex.Replace(questionInput.Content, @"\([^)]*\)", "()");

                    questionOutCar.Answer = questionInput.Answer.Trim().Replace(" ", "");
                    for (int i = 0; i < matches3.Count; i++)
                    {
                        switch (i)
                        {
                            case 0:
                                questionOutCar.OptionsA = Regex.Replace(matches3[0].Value, @"^.*?、", "");

                                break;
                            case 1:
                                questionOutCar.OptionsB = Regex.Replace(matches3[1].Value, @"^.*?、", "");
                                break;
                            case 2:
                                questionOutCar.OptionsC = Regex.Replace(matches3[2].Value, @"^.*?、", "");
                                break;
                            case 3:
                                questionOutCar.OptionsD = Regex.Replace(matches3[3].Value, @"^.*?、", "");
                                break;
                            default:
                                break;
                        }

                    }
                    outCar.Add(questionOutCar);
                }
                using (var strem = File.Create("output3.xlsx"))
                {
                    strem.SaveAs(outCar);
                }
            }

        }
    }
    public class QuestionCar
    {
        [ExcelColumnName("序号")]
        public int? Num { get; set; }
        [ExcelColumnName("内容")]
        public string Content { get; set; }
        [ExcelColumnName("选项")]
        public string Options { get; set; }
        [ExcelColumnName("答案")]
        public string Answer { get; set; }

    }




    public class QuestionOutCar
    {
        [ExcelColumnName("序号")]
        public int? Num { get; set; }
        [ExcelColumnName("题目")]
        public string Content { get; set; }
        [ExcelColumnName("答案1")]
        public string OptionsA { get; set; }
        [ExcelColumnName("答案2")]
        public string OptionsB { get; set; }
        [ExcelColumnName("答案3")]
        public string OptionsC { get; set; }
        [ExcelColumnName("答案4")]
        public string OptionsD { get; set; }
        [ExcelColumnName("正确答案")]
        public string Answer { get; set; }
        [ExcelColumnName("题型")]
        public string QuestionType { get; set; } = "单选题";
        [ExcelColumnName("备注")]
        public string Remark { get; set; }

        [ExcelColumnName("区域")]
        public string ApplyArea { get; set; } = "大庆市";
    }
}
